
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html style="height: 100%">
<head>
    <meta charset="utf-8">
    <title>实时空气湿度</title>
    <style>
        #nowtime {
            display: block;
            width: 300px;
            text-align: center;
            margin: 0 auto;
        }
    </style>
</head>
<body  style="height: 100%; margin: 0">
<%--
onload="setInterval('testRes()',1000);"
--%>
<h2 id="nowtime">实时温度</h2>
<div id="container" style="height: 100%"></div>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>

<script type="text/javascript">
    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);
    var app = {};
    var IllumData="";
    var option;


    //连接webSocket获取实时温湿度数据
    if (window.WebSocket) {
        var ws = new WebSocket('ws://39.98.198.224:888');
        ws.onopen = function(e) {
            console.log("连接服务器成功");
            ws.send(" ");
        }
        ws.onmessage = function(e) {
            IllumData=e.data;
            IllumData=IllumData.split(" ");

        }
        ws.onclose = function(e) {
            console.log("服务器关闭");
        }
        ws.onerror = function() {
            console.log("连接出错");
        }
    }


    //配置图表
    option = {
        series: [{
            type: 'gauge',
            axisLine: {
                lineStyle: {
                    width: 30,
                    color: [
                        [0.3, '#67e0e3'],
                        [0.7, '#37a2da'],
                        [1, '#fd666d']
                    ]
                }
            },
            pointer: {
                itemStyle: {
                    color: 'auto'
                }
            },
            axisTick: {
                distance: -30,
                length: 8,
                lineStyle: {
                    color: '#fff',
                    width: 2
                }
            },
            splitLine: {
                distance: -30,
                length: 30,
                lineStyle: {
                    color: '#fff',
                    width: 4
                }
            },
            axisLabel: {
                color: 'auto',
                distance: 40,
                fontSize: 20
            },
            detail: {
                valueAnimation: true,
                formatter: '{value} LX',
                color: 'auto'
            },
            data: [{
                value:0
            }]
        }]
    };
    option.series[0].max =400;

    setInterval(function () {
        option.series[0].data[0].value =IllumData[4];
        myChart.setOption(option, true);
        document.getElementById('nowtime').innerText=(IllumData[0]+" "+IllumData[1]);
    }, 1600);

    if (option && typeof option === 'object') {
        myChart.setOption(option);
    }

</script>
</body>
</html>

